//
//  LFSoftwareController.m
//  ServiceBaZhou
//
//  Created by 刘江涛 on 2017/8/24.
//  Copyright © 2017年 weierda. All rights reserved.
//

#import "LFSoftwareController.h"

#import "SoftWareModel.h"

@interface LFSoftwareController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *dataArray;

@property (nonatomic,strong) NSArray *myArray;

@end

@implementation LFSoftwareController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNavigation:@"企业证书"];
    
    [self createTableView];
    
    [self loadData];
    
    
    _myArray = @[@"",@"软件简称：小米仓储",@"登记号：928371825",@"登记批准日期：2017-09-20"];
    
}

- (void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, Width, Height - 64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = NO;
    
    [self.view addSubview:_tableView];
}

- (void)loadData{
    NSMutableDictionary *para = [NSMutableDictionary dictionaryWithCapacity:0];
    [para setObject:Token forKey:@"key"];
    [para setObject:_companyName forKey:@"personName"];
    [para setObject:@"50" forKey:@"pageSize"];
    
    [CFHttpTools getRequest:@"CopyRight/GetSoftwareCr" params:para success:^(id responseObj) {
        //
        CFLog(@"%@",responseObj);
        
        if(![responseObj[@"Result"] isKindOfClass:[NSArray class]]){
            if([CFToolUtil isBlankString:responseObj[@"Result"]]){
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 64, Width - 100 , Width - 100)];
                imageView.image = [UIImage imageNamed:@"nodata"];
                [self.tableView addSubview:imageView];
                
                UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, Width - 20, Width, 20)];
                label.text = @"暂无数据";
                label.textColor = [UIColor grayColor];
                label.textAlignment = NSTextAlignmentCenter;
                [self.tableView addSubview:label];
            }
        }else{
            
            NSArray *softwareArray = responseObj[@"Result"];
            
            JSONModelArray *modelArray = [[JSONModelArray alloc]initWithArray:softwareArray modelClass:[SoftWareModel class]];
            
            self.dataArray = [NSMutableArray array];
            
            [self.dataArray addObjectsFromArray:(NSArray *)modelArray];
            
            [_tableView reloadData];
            
        }
    } failure:^(NSError *error) {
        //
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return 30;
    }else{
        return 20;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *iden = @"iden";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    SoftWareModel *model = _dataArray[indexPath.section];
    
    if(indexPath.row == 0){
        cell.textLabel.text = model.Name;
        cell.textLabel.font = [UIFont systemFontOfSize:12];
        cell.textLabel.textColor = [UIColor blackColor];
        return cell;
    }else{
        NSString *showStr = @"";
        if(indexPath.row == 1){
            showStr = [NSString stringWithFormat:@"软件简称：%@",model.ShortName];
        }else if (indexPath.row == 2){
            showStr = [NSString stringWithFormat:@"登记号：%@",model.RegisterNo];
        }else{
            showStr = [NSString stringWithFormat:@"登记批准日期：%@",[model.RegisterAperDate substringToIndex:10]];
        }
        cell.textLabel.text = showStr;
        cell.textLabel.textColor = [UIColor colorWithHexString:@"#A1A1A1"];
        cell.textLabel.font = [UIFont systemFontOfSize:10];
        return cell;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
